package com.example.child_protection.controller;

import com.example.child_protection.dto.base.BaseResponseDTO;
import com.example.child_protection.dto.request.SimpleIdRequestDTO;
import com.example.child_protection.dto.request.add.AttrValueInsertRequestDTO;
import com.example.child_protection.dto.request.find.AttrValueRequestDTO;
import com.example.child_protection.dto.request.find.CheckCodeRequestDTO;
import com.example.child_protection.dto.request.update.AttrValueUpdateRequestDTO;
import com.example.child_protection.dto.response.AttrValueListResponseDTO;
import com.example.child_protection.dto.response.AttrValueResponseDTO;
import com.example.child_protection.dto.response.CheckCodeResponseDTO;
import com.example.child_protection.service.AttrValueManageService;
import com.example.child_protection.service.AttrValueQueryService;
import com.example.child_protection.util.ContentType;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;

/**
 * 属性候选值管理控制层
 * @date 2018-11-2
 * @author Biz
 */
@RestController
@RequestMapping("attrValue")
@Api(value = "/api-attrValue", description = "属性候选值管理")
public class AttrValueController extends BaseController {

    @Autowired
    public AttrValueManageService attrValueManageService;

    @Autowired
    public AttrValueQueryService attrValueQueryService;

    @ApiOperation(value ="查询属性候选值", httpMethod = "POST",response = BaseResponseDTO.class )
    @RequestMapping(value = "/findId", method = RequestMethod.POST, produces = {ContentType.APPLICATION_JSON_UTF_8, ContentType.TEXT_XML_UTF_8})
    public AttrValueResponseDTO findId(SimpleIdRequestDTO requestDTO,HttpServletRequest request)throws Exception{
        logger.info("用户ID{},sessionId{}",request.getSession().getAttribute("user"),request.getSession().getId());
        AttrValueResponseDTO responseDTO = attrValueQueryService.findId(requestDTO);
        return responseDTO;
    }

    @ApiOperation(value ="查询属性候选值列表信息", httpMethod = "POST",response = BaseResponseDTO.class )
    @RequestMapping(value = "/findList", method = RequestMethod.POST, produces = {ContentType.APPLICATION_JSON_UTF_8, ContentType.TEXT_XML_UTF_8})
    public AttrValueListResponseDTO findList(AttrValueRequestDTO requestDTO, HttpServletRequest request)throws Exception{
        AttrValueListResponseDTO responseDTO = attrValueQueryService.findList(requestDTO);
        return responseDTO;
    }

    @ApiOperation(value ="检测候选值KEY是否重复", httpMethod = "POST",response = BaseResponseDTO.class )
    @RequestMapping(value = "/checkCode", method = RequestMethod.POST, produces = {ContentType.APPLICATION_JSON_UTF_8, ContentType.TEXT_XML_UTF_8})
    public CheckCodeResponseDTO checkCode(CheckCodeRequestDTO requestDTO, HttpServletRequest request)throws Exception{
        CheckCodeResponseDTO responseDTO = attrValueQueryService.checkCode(requestDTO);
        return responseDTO;
    }

    @ApiOperation(value ="添加属性候选值", httpMethod = "POST",response = BaseResponseDTO.class )
    @RequestMapping(value = "/insert", method = RequestMethod.POST, produces = {ContentType.APPLICATION_JSON_UTF_8, ContentType.TEXT_XML_UTF_8})
    public BaseResponseDTO insert(AttrValueInsertRequestDTO requestDTO)throws Exception{
        requestDTO.setCreatePersonId(this.getLoginUserId());
        requestDTO.setLastUpdatePersonId(this.getLoginUserId());
        BaseResponseDTO responseDTO = attrValueManageService.insert(requestDTO);
        return responseDTO;
    }

    @ApiOperation(value ="修改属性候选值", httpMethod = "POST",response = BaseResponseDTO.class )
    @RequestMapping(value = "/update", method = RequestMethod.POST, produces = {ContentType.APPLICATION_JSON_UTF_8, ContentType.TEXT_XML_UTF_8})
    public BaseResponseDTO update(AttrValueUpdateRequestDTO requestDTO)throws Exception{
        requestDTO.setLastUpdatePersonId(this.getLoginUserId());
        BaseResponseDTO responseDTO = attrValueManageService.update(requestDTO);
        return responseDTO;
    }

    @ApiOperation(value ="删除属性候选值", httpMethod = "POST",response = BaseResponseDTO.class )
    @RequestMapping(value = "/delete", method = RequestMethod.POST, produces = {ContentType.APPLICATION_JSON_UTF_8, ContentType.TEXT_XML_UTF_8})
    public BaseResponseDTO delete(SimpleIdRequestDTO requestDTO)throws Exception{
        requestDTO.setLastUpdatePersonId(this.getLoginUserId());
        BaseResponseDTO responseDTO = attrValueManageService.delete(requestDTO);
        return responseDTO;
    }

}
